﻿using System;
using LEDHelper;
using System.Runtime.InteropServices;
namespace LEDManager
{ 
    public partial class LEDUnit
    {
        #region==========WinAPI===========
        [DllImport("user32.dll")]
        public static extern IntPtr GetDC(IntPtr hwnd);
        [DllImport("user32.dll")]
        public static extern IntPtr ReleaseDC(IntPtr hc, IntPtr hDest);
        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowDC(IntPtr hwnd);
        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll")]
        public static extern int GetWindowRect(IntPtr hwnd, ref Rect lpRect);
        //[DllImport("gdi32.dll")]
        //public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
        [DllImport("GDI32.dll")]
        public static extern bool BitBlt(int hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int hdcSrc,int nXSrc, int nYSrc, int dwRop);
        [DllImport("gdi32.dll", ExactSpelling = true, PreserveSig = true, SetLastError = true)]
        public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);

        [DllImport("gdi32.dll", SetLastError = true)]
        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

        [DllImport("gdi32.dll")]
        public static extern bool DeleteObject(IntPtr hObject);
        [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 SetRect(ref SRECT rect, Int32 left, Int32 top, Int32 right, Int32 bottom);


        public enum TernaryRasterOperations : uint
        {
            /// <summary>dest = source</summary> 
            SRCCOPY = 0x00CC0020,
            /// <summary>dest = source OR dest</summary> 
            SRCPAINT = 0x00EE0086,
            /// <summary>dest = source AND dest</summary> 
            SRCAND = 0x008800C6,
            /// <summary>dest = source XOR dest</summary> 
            SRCINVERT = 0x00660046,
            /// <summary>dest = source AND (NOT dest)</summary> 
            SRCERASE = 0x00440328,
            /// <summary>dest = (NOT source)</summary> 
            NOTSRCCOPY = 0x00330008,
            /// <summary>dest = (NOT src) AND (NOT dest)</summary> 
            NOTSRCERASE = 0x001100A6,
            /// <summary>dest = (source AND pattern)</summary> 
            MERGECOPY = 0x00C000CA,
            /// <summary>dest = (NOT source) OR dest</summary> 
            MERGEPAINT = 0x00BB0226,
            /// <summary>dest = pattern</summary> 
            PATCOPY = 0x00F00021,
            /// <summary>dest = DPSnoo</summary> 
            PATPAINT = 0x00FB0A09,
            /// <summary>dest = pattern XOR dest</summary> 
            PATINVERT = 0x005A0049,
            /// <summary>dest = (NOT dest)</summary> 
            DSTINVERT = 0x00550009,
            /// <summary>dest = BLACK</summary> 
            BLACKNESS = 0x00000042,
            /// <summary>dest = WHITE</summary> 
            WHITENESS = 0x00FF0062
        }

        #endregion
        #region========LED Sender.dll==============
        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_Open(ref PDeviceParam param, Int32 Notify, Int32 Window, Int32 Message);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_Query(Int32 dev, Byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_Close(Int32 dev);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_AdjustTime(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_SendToScreen(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_GetPower(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_SetPower(Int32 dev, byte Address, string Host, UInt16 port, int Power);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_GetBrightness(Int32 dev, byte Address, string Host, UInt16 port);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern void LED_SetBrightness(Int32 dev, byte Address, string Host, UInt16 port, Int32 Brightness);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_GetNotifyMessage(ref PNotifyMessage Notify);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_GetOption(int Index);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 LED_SetOption(int Index, Int32 Value);
        /// <summary>
        ///   MakeRoot说明
        ///   Function  MakeRoot(RootType: Integer; ScreenType: Integer): Integer; Stdcall; External LEDSender;
        ///   RootType: 可选ROOT_PLAY或ROOT_DOWNLOAD
        ///    ROOT_PLAY: 表示显示内容仅播放，无需保存，控制卡掉电后不再需要显示
        ///    ROOT_DOWNLOAD: 表示显示内容需要保存在主板中，当控制卡上电后自动播放
        ///    (注意：控制卡只能保存1M的数据)
        ///    ScreenType: 必须和控制卡的设置相同，否则将不会显示
        /// </summary>
        /// <param name="RootType"></param>
        /// <param name="ScreenType"></param>
        /// <returns></returns>
        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 MakeRoot(Int32 RootType, Int32 ScreenType);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddLeaf(Int32 DisplayTime); //DisplayTime单位为毫秒

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddWindow(IntPtr hdc, Int32 width, Int32 height, ref SRECT rect, Int32 method, Int32 speed, Int32 transparent);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddDateTime(ref SRECT rect, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor, Int32 format);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddString(string str, ref SRECT rect, Int32 method, Int32 speed, Int32 transparent, Int32 fontset, Int32 fontcolor);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddText(string str, ref SRECT rect, Int32 method, Int32 speed, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddMovie(string filename, ref SRECT rect, Int32 stretch);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddCountUp(ref SRECT rect, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor, Int32 format, LPSYSTEMTIME starttime);

        [DllImport("LEDSender.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern Int32 AddCountDown(ref SRECT rect, Int32 transparent, string fontname, Int32 fontsize, Int32 fontcolor, Int32 format, LPSYSTEMTIME endtime);

        #endregion
    }  
  
}
